<template>
    <div>
        <el-dialog
            width="30%"
            title="批量设置员工在职状态"
            :visible.sync="visible"
            :close-on-click-modal="false">

            <div class="table_form_wrap">

                <el-form ref="form" :inline="false" :model="form" :rules="rules" @keyup.enter.native="handleSubmit()" label-width="150px">
                    <div class="form_scroll_wrap">
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="在职状态" prop="status">
                                    <DictSelect code="YGZT" :selectVal.sync="form.status"></DictSelect>
                                </el-form-item>
                            </el-col>

                            <el-col :span="24" v-if="form.status == '1' || form.status == '2' || form.status == '3'">
                                <el-form-item label="离职日期" prop="quitDate">
                                    <el-date-picker
                                        style="width: 80%"
                                        v-model="form.quitDate"
                                        type="date"
                                        placeholder="选择日期"
                                        value-format="yyyy-MM-dd">
                                    </el-date-picker>
                                </el-form-item>
                            </el-col>

                            <!-- <el-col :span="24">
                                <el-form-item label="开始日" prop="startDate">
                                    <el-date-picker
                                        style="width: 80%"
                                        v-model="form.startDate"
                                        type="date"
                                        placeholder="选择日期"
                                        value-format="yyyy-MM-dd">
                                    </el-date-picker>
                                </el-form-item>
                            </el-col> -->

                        </el-row>
                    </div>
                </el-form>
            </div>


            <div slot="footer" class="dialog-footer">
                <el-button @click="visible = false">取 消</el-button>
                <el-button @click="handleSubmit()" type="primary" :submitLoading="submitLoading">提 交</el-button>
            </div>

        </el-dialog>
    </div>
</template>

<script>
import DictSelect from '@/views/system/sysdict/components/dict-select'
export default {
    components: {
        DictSelect
    },
    data() {
        return {
            visible: false,
            submitLoading: false,

            form: {
                ids: null,
                quitDate: null,
                status: null
            },
            rules: {
                status: [{required: true, message: '在职状态不能为空', trigger: 'blur'}],
                quitDate: [{required: true, message: '离职日期不能为空', trigger: 'blur'}],
            },
        }
    },

    methods: {
        init(rows) {
            let ids = []
            rows.forEach(item => {
                ids.push(item.id)
            })
            const refs = this.$refs
            // 情况表单数据
            this.form.ids = ids

            this.visible = true

            this.$nextTick(() => {
                refs['form'].resetFields()
            })
        },

        /**
         * 提交表单
         */
        async handleSubmit() {
            const refs = this.$refs
            this.submitLoading = true
            const valid = await refs['form'].validate().catch(() => {})
            if (valid) {
                const res = await this.$http({
                    url: `/hr/employee/batchSettingStatus`,
                    method: 'POST',
                    data: this.form
                })
                if (this.ResultMessage(res)) {
                    this.$emit('refreshDataList')
                    this.submitLoading = false
                    this.visible = false
                } else {
                    this.submitLoading = false
                }
            } else {
                this.submitLoading = false
            }
        }

    }
};
</script>

<style lang="scss" scoped>
.table_form_wrap{
    height: 200px;
}
</style>
